import React, { useState } from 'react';
import s from './style.module.css';
import Chart from './chart';
import Info from './info';
export default function infoBox({ data, type }) {
  const modules=localStorage.info?JSON.parse(localStorage.info).modules:[]
  const [chartD, setChartD] = useState();
  React.useEffect(() => {
    if (!data.summary) {
      return;
    }
    const summary = data.summary;
    const chartD_ = { data: { CRITICAL:0,HIGH: 0, MEDIUM: 0, LOW: 0 }, score: 0 };
    Object.keys(summary).forEach((e) => {
      Object.keys(summary[e]).forEach((e_) => {
        if (e_ === 'INFO') {
          return;
        }
        e_ !== 'num' && (chartD_.data[e_] += summary[e][e_]);
      });
    });
    chartD_.score = summary.score;
    setChartD(chartD_);
  }, [data]);
  return (
    <>
      <div className={s.box1_1}>
        <Chart chartD={chartD} />
      </div>
      <div className={s.box1_2}>{data && <Info data={data} type={type} modules={modules}/>}</div>
    </>
  );
}
